﻿using AnlianCommon.Common.Domains.BankCustomers;
using AnlianCommon.Common.DTO;
using AnlianCommon.Common.Infrastructure.IRepository;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace SheepCommon.API.Vendors
{
    public class BankaccountBackFillHandler : IRequestHandler<BankaccountBackFillCommand, Result>
    {
        private readonly IBaseRepository<Bankaccount> _bankaccountRepository;

        public BankaccountBackFillHandler(IBaseRepository<Bankaccount> bankaccountRepository)
        {
            _bankaccountRepository = bankaccountRepository;
        }
        /// <summary>
        /// 银行账户信息反填业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(BankaccountBackFillCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            try
            {
                var bankaccountById = await (await _bankaccountRepository.GetAll()).Where(c => c.BankaccountId == request.BankaccountId).FirstOrDefaultAsync();
                if (bankaccountById != null)
                {
                    result.Data = bankaccountById;
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
